package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.common.constants.ClueStatusConstants;
import com.qk.domain.clue.ClueDO;
import com.qk.domain.clue.CluePoolDO;
import com.qk.dto.Clue.*;
import com.qk.entity.Clue;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author: zyx
 * @created: 2025-10-13-20:11
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/clues")
public class ClueController {

    @Autowired
    private ClueService clueService;
    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO dto) {
        log.info("添加线索：{}", dto);
        clueService.add(dto);
        return Result.success();
    }

    @GetMapping
    public Result page(ClueListDTO dto) {
        PageResult<ClueDO> result =clueService.selectPage(dto);
        log.info("分页查询结果：{}", result);
        return Result.success(result);
    }

    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result updateClueById(@PathVariable Integer clueId, @PathVariable Integer userId) {
        clueService.updateById(Clue.builder()
                .id(clueId)
                .updateTime(LocalDateTime.now())
                .userId(userId)
                .status(ClueStatusConstants.WAIT_FOLLOW_UP)
                .build()
        );
        log.info("分配线索：{}", clueId);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        ClueVO vo =clueService.getClueInfoById(id);
        return Result.success(vo);
    }
    @LogAnno
    @PutMapping
    public Result followUpClue(@RequestBody UpdateClueDTO dto) {
        clueService.followUpClue(dto);
        return Result.success();
    }


    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/false/{id}")
    public Result fakeClue(@PathVariable Integer id, @RequestBody FalseDTO dto){
        clueService.fakeClue(id,dto);
        return Result.success();
    }
    @GetMapping("/pool")
    public Result poolPage(CluePoolListDTO dto) {
        PageResult<CluePoolDO> result =clueService.poolPage(dto);
        log.info("线索池分页查询结果：{}", result);
        return Result.success(result);
    }
}
